// 前端token调试脚本
// 在浏览器控制台中运行

console.log('=== Token调试开始 ===');

// 1. 检查localStorage中的token
const token = localStorage.getItem('token');
console.log('1. localStorage中的token:', token ? token.substring(0, 50) + '...' : 'null');

// 2. 检查用户store中的token
import { useUserStore } from '@/stores/user';
const userStore = useUserStore();
console.log('2. 用户store中的token:', userStore.token ? userStore.token.substring(0, 50) + '...' : 'null');

// 3. 测试API请求
async function testAPI() {
  console.log('3. 测试API请求...');
  
  try {
    const response = await fetch('/api/users/?page=1&per_page=10&search=', {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      }
    });
    
    console.log('响应状态:', response.status);
    console.log('响应头:', Object.fromEntries(response.headers.entries()));
    
    const data = await response.text();
    console.log('响应内容:', data);
    
  } catch (error) {
    console.error('请求失败:', error);
  }
}

// 4. 测试axios请求
async function testAxios() {
  console.log('4. 测试axios请求...');
  
  try {
    const axios = await import('axios');
    const response = await axios.default.get('/api/users/?page=1&per_page=10&search=', {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });
    
    console.log('axios响应:', response.data);
    
  } catch (error) {
    console.error('axios请求失败:', error.response?.data || error.message);
  }
}

// 运行测试
testAPI();
testAxios();

console.log('=== Token调试结束 ==='); 